﻿using UnityEngine;
using GameFramework;
using UnityGameFramework.Runtime;

namespace MYSTARFORCE
{
    /// <summary>
    /// 菜单界面脚本
    /// </summary>
    public class MenuForm : UGuiForm
    {
        /// <summary>
        /// 退出按钮
        /// </summary>
        [SerializeField]
        private GameObject m_BtnQuit = null;

        /// <summary>
        /// 菜单流程
        /// </summary>
        private ProcedureMenu m_ProcedureMenu = null;

        /// <summary>
        /// 打开UIForm时
        /// </summary>
        /// <param name="userData"></param>
        protected override void OnOpen(object userData)
        {
            base.OnOpen(userData);

            m_ProcedureMenu = (ProcedureMenu)userData;
            // 如果界面不存在，就抛出一条提示
            if(m_ProcedureMenu == null)
            {
                Log.Warning("ProcedureMenu is invalid when open MenuForm");
            }
            return;
        }

        /// <summary>
        /// 关闭UIForm时
        /// </summary>
        /// <param name="userData"></param>
        protected override void OnClose(object userData)
        {
            m_ProcedureMenu = null;

            base.OnClose(userData);
        }
        /// <summary>
        /// 点击开始按钮
        /// </summary>
        public void OnBtnStartClick()
        {
            // 进入菜单流程
            m_ProcedureMenu.IsStartGame = true;
        }

        /// <summary>
        /// 点击设置按钮
        /// </summary>
        public void OnBtnSettingClick()
        {
            // 打开设置界面
            GameEntry.UI.OpenUIForm(UIFormId.SettingForm);
        }

        /// <summary>
        /// 点击制作团队按钮
        /// </summary>
        public void OnBtnAboutClick()
        {
            // 打开制作团队界面
            GameEntry.UI.OpenUIForm(UIFormId.AboutForm);
        }

        /// <summary>
        /// 点击退出按钮
        /// </summary>
        public void OnBtnQuitClick()
        {
            //TODO: 原版游戏在退出之时会弹出一个确认是否要退出游戏的对话框，我们过会儿再做它
            // 关闭游戏
            UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Quit);
        }
    }
}